package com.tanhua.app.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.app.service.MessagesService;
import com.tanhua.domain.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping(value = "/messages")
public class MessageController {

    @Autowired
    private MessagesService messageService;

    @PostMapping(value = "/contacts", name = "互加好友")
    public ResponseEntity contacts(@RequestBody Map map) throws ClientException, IOException {
        long userId = Long.parseLong(map.get("userId").toString());
        return messageService.contacts(userId, UserHolder.getUser().getId());
    }

    @GetMapping(value = "/contacts", name = "查询好友列表")
    public ResponseEntity findFriendPage(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize,
                                         String keyword) throws ClientException, IOException {

        return messageService.findFriendsList(page, pagesize,UserHolder.getUser().getId());
    }


    @GetMapping(value = "/likes", name = "查询点赞用户")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize) throws ClientException, IOException {

        return messageService.findPageUserInfo(page, pagesize,1);
    }

    @GetMapping(value = "/comments", name = "查询评论用户")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize) throws ClientException, IOException {

        return messageService.findPageUserInfo(page, pagesize,2);
    }

    @GetMapping(value = "/loves", name = "查询喜欢用户")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize) throws ClientException, IOException {

        return messageService.findPageUserInfo(page, pagesize,3);
    }

}